package com.swq.java.code.chapter15.code03;

import java.util.HashSet;
import java.util.Set;

public class Customer{
    public static void main(String[] args) {
        Set<Customer> customers = new HashSet<>();
        customers.add(new Customer("Tom", 21));
        customers.add(new Customer("Tom", 21));
        System.out.println(customers.size());
    }

    private String name;
    private int age;

    public Customer(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return this.name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return this.age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof Customer)) return false;
        final Customer other = (Customer) o;

        if (this.name.equals(other.getName()) && this.age == other.getAge())
            return true;
        else
            return false;
    }

    public int hashCode() {
        int result;
        result = (name == null ? 0 : name.hashCode());
        result = 29 * result + age;
        return result;
    }
}